package binarySearch;

public class search {
    public int search(int[] nums, int target) {
        int m=nums.length;
        int right=m-1;
        int left=0;
        while(left<=right){
            int mid=(left+right+1)/2;
            if(nums[mid]==target){
                return mid;
            }else if(nums[mid]>target) right=mid-1;
            else if(nums[mid]<target) left=mid+1;
        }
        return -1;
    }
}
